package com.example.droideep.fragment.animstudy;


import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.graphics.PointF;
import android.util.Log;
import android.view.animation.LinearInterpolator;

import com.example.droideep.R;
import com.example.droideep.common.activities.SimpleFragmentBase;

import butterknife.InjectView;
import butterknife.OnClick;
import droideep.library.widget.FloatingActionButton;

/**
 * A simple {@link SimpleFragmentBase} subclass.
 */
public class ParabolicMotionFragment extends SimpleFragmentBase {

    public static final String TAG = ParabolicMotionFragment.class.getSimpleName();

    @InjectView(R.id.floating_action_button)
    FloatingActionButton mFab;

    public static ParabolicMotionFragment newInstance() {
        return new ParabolicMotionFragment();
    }

    @Override
    protected int getContentResId() {
        return R.layout.fragment_parabolic_motion;
    }

    @OnClick(R.id.parabolic_motion)
    public void parabolicMotion() {
        ValueAnimator valueAnimator = new ValueAnimator();
        valueAnimator.setDuration(3000);
        valueAnimator.setObjectValues(new PointF(0, 0));
        valueAnimator.setInterpolator(new LinearInterpolator());
        valueAnimator.setEvaluator(new TypeEvaluator<PointF>() {
            @Override
            public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
                Log.d(TAG, fraction * 3 + "");
                PointF point = new PointF();
                point.x = 200 * fraction * 3;
                point.y = 0.5f * 200 * (fraction * 3 * fraction * 3);
                return point;
            }
        });

        valueAnimator.start();
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                PointF pointF = (PointF) animation.getAnimatedValue();
                mFab.setX(pointF.x);
                mFab.setY(pointF.y);
            }
        });
    }


}
